# Maintainer: Bruno Pagani <archange@archlinux.org>

pkgname=adios2
pkgver=2.8.3
pkgrel=4
pkgdesc="The Adaptable Input/Output System version 2"
arch=(loong64 x86_64)
url="https://adios2.readthedocs.io/en/latest/"
license=(Apache)
depends=(blosc bzip2 glibc gcc-libs hdf5 libfabric libpng nlohmann-json
         openmpi pugixml pybind11 sz yaml-cpp zeromq zfp zlib)
# with mgard does not build currently, not time to investigate
makedepends=(cmake gcc-fortran gtest python python-mpi4py python-numpy)
source=(https://github.com/ornladios/ADIOS2/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
        https://github.com/ornladios/ADIOS2/commit/bc67316d.patch
        https://github.com/ornladios/ADIOS2/commit/c3967d39.patch
        https://github.com/ornladios/ADIOS2/commit/a04395e0.patch
        https://github.com/ornladios/ADIOS2/commit/a6b6c668.patch)
sha256sums=('4906ab1899721c41dd918dddb039ba2848a1fb0cf84f3a563a1179b9d6ee0d9f'
            '7998b6624cafefadd800158b4b5184c341f93dd446f55237cdfbf1f025bf4823'
            '8edc0438b4e84afa51d730b94355cd7f28620351ab3bd438a46272fb6cd91aa1'
            'da2dacee292eef376c488b4efc2b7fe23b619da278828ef6d74b6549ba1caea6'
            'ca2998c08abd157d6d27866bdb8c964327a46f05fd273ee6a0fa1622dff6b80e')

prepare() {
# Fix build with HDF5 1.14
  patch -d ${pkgname^^}-${pkgver} -p1 < bc67316d.patch
  patch -d ${pkgname^^}-${pkgver} -p1 < c3967d39.patch
  patch -d ${pkgname^^}-${pkgver} -p1 < a04395e0.patch
  patch -d ${pkgname^^}-${pkgver} -p1 < a6b6c668.patch
}

build() {
  cmake -B build -S ${pkgname^^}-${pkgver} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_SKIP_RPATH=ON \
    -DADIOS2_USE_EXTERNAL_DEPENDENCIES=ON \
    -DADIOS2_HAVE_HDF5_VOL=OFF \
    -DADIOS2_BUILD_EXAMPLES=OFF #\
    #-DMGARD_INCLUDE_DIR=/usr/include/mgard
    #-DADIOS2_HAVE_HDF5_VOL needs hdf5-openmpi
  make VERBOSE=1 -C build
}

package() {
  make -C build DESTDIR="${pkgdir}" install
}
